package com.heima.schedule.client;

import com.heima.feign.client.ScheduleFeignClient;
import com.heima.model.schedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/task")
public class ScheduleClient implements ScheduleFeignClient {

    @Autowired
    private TaskService taskService;

    /**
     * 添加任务
     *
     * @param task 任务对象
     */
    @Override
    @PostMapping("/add")
    public void addTask(@RequestBody Task task) {
        taskService.saveTask(task);
    }

    /**
     * 按照类型和优先级来拉取任务
     *
     * @param type
     * @param priority
     */
    @Override
    @GetMapping("/pull/{type}/{priority}")
    public Task pull(@PathVariable("type") int type,@PathVariable("priority")  int priority) {
        return taskService.pullTask(type,priority);
    }
}
